﻿<div ng-controller="Customer_EditC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">报备审核</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="h4">编辑报备审核</span>
                        </div>
                        <div class="panel-body">
                            <div class="form-group">
                                <label>简称 <em class="text-muted">(2-15字符)</em></label>
                                <input type="text" class="form-control" ng-model="data.ShortName" required minlength="2" maxlength="15" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>名称</label>
                                <input type="text" class="form-control" ng-model="data.Name" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label style="margin-right: 10px;">是否个人账户</label>
                                <label class="i-switch bg-info">
                                    <input type="checkbox" ng-model="data.IsPersonal">
                                    <i></i>
                                </label>
                            </div>

                            <div class="form-group">
                                <label>地区 </label>
                                <div class="input-group ">
                                    <!--<span class="input-group-addon">省</span>-->
                                    <!--<select required class="form-control" ng-options="x.FillName for x in districts" ng-model="selectedDistrict1"></select>-->
                                    <!--<span class="input-group-addon">市</span>-->
                                    <!--<select required class="form-control" ng-options="y.Id as y.Name for y in selectedDistrict1.Children  track by x.Id" ng-model="data.District.Id" name="District"></select>-->
                                    <span class="input-group-addon" >省</span>
                                    <input type="text" disabled class="form-control" ng-model="data.District.Parent.Name">
                                    <!--<select class="form-control" ng-options="x.FillName for x in districts" ng-model="selectedDistrict1" readonly="readonly"></select>-->
                                    <span class="input-group-addon" >市</span>
                                    <input type="text" disabled class="form-control" ng-model="data.District.Name">
                                    <!--<select class="form-control" ng-options=" y as y.Name for y in selectedDistrict1.Children track by y.Id" ng-model="data.District" readonly="readonly"></select>-->
                                </div>
                            </div>

                            <div class="form-group">
                                <label>地址</label>
                                <input type="text" class="form-control" ng-model="data.Address" readonly="readonly">
                            </div>
                            <!--<div class="form-group">
                                <label>联系人</label>
                                <input type="text" class="form-control" ng-model="data.Contacts" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>电话</label>
                                <input type="text" class="form-control" readonly="readonly" ng-model="data.ContactPhone" required ng-pattern="/^[1][3-8]\d{9}$/" value="{{datauser.Phone}}">
                            </div>


                            <div class="form-group">
                                <label>财务</label>
                                <input type="text" class="form-control" ng-model="data.Accountant" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>财务电话</label>
                                <input readonly="readonly" type="text" class="form-control" ng-model="data.AccountantPhone" required ng-pattern="/^[1][3-8]\d{9}$/" value="{{datauser.Phone}}">
                            </div>-->
                            <!--------------------动态加载联系人行 Start--------------------------------------------------->

                            <div class="form-group">
                                <div id="Contacts-wraper">
                                    <div class="Contacts-inner" ng-repeat="x in data.CustomerContacts">
                                        <label>联系人{{$index + 1}}</label>
                                        <input type="text" ng-model="x.ContactUser" disabled>
                                        <label>电话(必填)</label>
                                        <input type="text" ng-model="x.ContactPhone" required ng-pattern="/^[1][3-8]\d{9}$/" disabled>
                                    </div>
                                    <!--<button type="button" class="btn btn-default" ng-click=" AddContact()">新增</button>
                                    <button type="button" class="btn btn-default" ng-click="remove()">删除</button>-->
                                </div>
                            </div>



                            <div class="form-group">
                                <div id="Contacts-wraper">
                                    <div class="Contacts-inner" ng-repeat="x in data.AccountantContacts">
                                        <label>财务{{$index + 1}}</label>
                                        <input type="text" ng-model="x.ContactUser" disabled>
                                        <label>财务电话</label>
                                        <input type="text" ng-model="x.ContactPhone" ng-pattern="/^[1][3-8]\d{9}$/" disabled>
                                    </div>
                                    <!--<button type="button" class="btn btn-default" ng-click=" AddAccountantContact()">新增</button>
                                    <button type="button" class="btn btn-default" ng-click="removeAccountant()">删除</button>-->
                                </div>
                            </div>
                            <!--------------------End--------------------------------------------------->
                            <div class="form-group">
                                <label>客户专员</label>
                                <input type="text" readonly="readonly" class="form-control" ng-model="data.ClientManager.Name" readonly="readonly">
                            </div>
                            <!--<div class="form-group">
                                <label>户头</label>
                                <input type="text" disabled class="form-control" ng-model="data.Accounts.length" />
                            </div>-->

                            <div class="form-group">
                                <label>身份证号</label>
                                <input type="text" class="form-control" ng-model="data.IDCode" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>信用代码</label>
                                <input type="text" class="form-control" ng-model="data.CreditID" readonly="readonly">
                            </div>

                            <!--<div class="form-group">-->
                            <!--<label>状态</label>-->
                            <!--<input type="text" class="form-control" ng-model="data.ApprovalState">-->
                            <!--</div>-->
                            <div class="form-group">
                                <label>备注</label>
                                <input type="text" class="form-control" ng-model="data.Remarks" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>评分</label>
                                <input type="text" class="form-control" ng-model="data.CreditScore" readonly="readonly">
                            </div>
                            <div class="form-group">
                                <label>历史记录</label>
                                <div ng-bind-html="trustAsHtml(data.Record)"></div>
                            </div>
                        </div>
                        <footer class="panel-footer text-right bg-light lter">
                            <button type="button" ng-disabled="data.ApprovalState!=0" class="btn btn-success" ng-click="pass(true)">确认报备</button>
                            <button type="button" ng-disabled="data.ApprovalState!=0" class="btn btn-warning" ng-click="pass(false)">驳回报备</button>
                            <button type="button" class="btn" ng-click="goback();">取消</button>
                        </footer>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
.controller("Customer_EditC", function ($scope, $state, $http, $stateParams) {
    console.log($stateParams.id);
    $http.get("/api/Customer/Detail", { params: { "id": $stateParams.id } })
       .then(function (res) {
           $scope.data = res.data;
           console.log($scope.data.District);
       })
       .then(function (error) {
           if (error) {
               alert("数据获取失败");
           }
       });
    //    //获取地市
    //$http({
    //    url: "/api/District",
    //    method: "GET"
    //})
    //    .then(function (res) {
    //        $scope.districts = res.data;
    //        if ($scope.data.District) {
    //            for (var i = 0; i < $scope.districts.length; i++) {
    //                if ($scope.districts[i].Id == $scope.data.District.Parent.Id) {
    //                    $scope.selectedDistrict1 = $scope.districts[i];
    //                    break;
    //                }
    //            }
    //        }
    //    })
    //    .then(function (error) {
    //        if (error) {
    //            console.log("error");
    //        }
    //    });

    $scope.goback = function () {
        debugger;
        if ($stateParams.from=="0") {
            $state.go('app.Customer_List');
        }
        else if ($stateParams.from == "1") {
            $state.go('app.Customer_ConfirmList');
        }
    }

        $scope.edit = function () {

        $http.put("/api/Customer", $scope.data)
       .then(function (res) {
           alert("保存成功");
       }).then(function (error) {
           if (error) {
               alert("处理失败");
           }
       })
        ;
    };
    //    户头管理
    $scope.pass = function (isPass) {
        $http.put("/api/Customer", $scope.data)
      .then(function (res) {
          $http.put("/api/Customer/Confirm?customerId=" + $scope.data.Id + "&isPass=" + isPass)
         .then(function (res) {
             alert("提交成功");
              $state.go('app.Customer_ConfirmList');
          }, function (error) {
             if (error) {
                 alert("处理失败,请稍后重试");
             }
         });
      }).then(function (error) {
          if (error) {
              alert("处理失败,请稍后重试");
          }
      })
        ;

    }

    $scope.trustAsHtml = function (content) {
        return content;
        //return content != undefined ? content.replace(/通过/g, "通过<br/>").replace(/驳回/g, "驳回<br/>") : "";
    };
})

</script>